import { PNT, setNavBarTitle, showToast, pushPagePath, scrollLoadList, checkMobile } from "../../../../utils/utils";
import { AddShop } from "../../../../utils/apis";
// pages/member/weidian/kaidian/kaidian.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (opt) {
    setNavBarTitle(PNT.order.main);
    this.loginModal = this.selectComponent("#login-modal");
    var info = wx.getStorageSync('userInfo')
    this.setData({
      status: opt.status || 0,
      info: info
    });
  },

  bindinut(e){
    var items = e.currentTarget.dataset;
    if(items.type == 'shop_name'){
      this.setData({shop_name:e.detail.value})
    }else if(items.type == 'real_name'){
      this.setData({ real_name: e.detail.value })
    }else if(items.type == 'mobile'){
      this.setData({ mobile: e.detail.value })
    }else if(items.type == 'QQ'){
      this.setData({ qq: e.detail.value })
    }
  },
  submitParam(){
    if(!this.data.shop_name){
      wx.showToast({
        title: '请输入店铺名',
        icon:'none',
      })
      return;
    }
    if(!this.data.real_name){
      wx.showToast({
        title: '请输入真实姓名',
        icon:'none'
      })
      return;
    }
    if (!checkMobile(this.data.mobile)) {
      wx.showToast({
        title: '请输入合法手机号',
        icon:'none'
      })
      return;
    }
    let qq = /^[1-9][0-9]{5,10}$/;
    if(!qq.test(this.data.qq)){
      wx.showToast({
        title: '请输入合法QQ号',
        icon:'none'
      })
      return;
    }
    var data = {};
    data.user_id = this.data.info.user_id;
    data.shop_name = this.data.shop_name;
    data.real_name = this.data.real_name;
    data.qq = this.data.qq;
    data.mobile = this.data.mobile;
    AddShop(data).then(res=>{
      if(res.error_code == 10000){
        wx.showToast({
          title: '添加成功',
          icon:'none'
        })
        setTimeout(function(){
          wx.navigateBack({
            delta:1,
          })
        },1500)
      }else{
        wx.showToast({
          title: '系统繁忙',
          icon: 'none'
        })
        setTimeout(function () {
          wx.navigateBack({
            delta: 1,
          })
        }, 1500)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})